package com.wwg.market.ui.dashboard.client.widgets;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.mobileares.midp.widgets.client.button.ButtonBar;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-12-5
 * Time: 18:01:09
 * To change this template use File | Settings | File Templates.
 */
public abstract class PageItem<T> extends Composite {
    protected ButtonBar bar;
    protected SimplePanel mainPanel;
    protected VerticalPanel container;
    private MyPage page;

    public PageItem() {
        initItemWidgets();
    }

    public PageItem(MyPage page) {
        this();
        setPage(page);
    }

    public MyPage getPage() {
        return page;
    }

    public void setPage(MyPage page) {
        this.page = page;
    }

    protected void initItemWidgets() {
        container = new VerticalPanel();
        container.setWidth("100%");
        container.setSpacing(1);
        initWidget(container);
        initMenu();
        mainPanel = new SimplePanel();
        container.add(mainPanel);
        processMain(mainPanel);
    }

    private void initMenu() {
        bar = new ButtonBar();
        bar.setWidth("100%");
        processMenu(bar);
        if (bar.getButtons().hasNext())
            container.add(bar);
    }

    protected abstract void processMain(SimplePanel mainPanel);

    protected abstract void processMenu(ButtonBar bar);


    abstract public void initModel();

    abstract public void ddOutModel(T ob);


}
